<html>
<body>

<form action="calculator.php" method="GET">
Expression: <input type="text" name="Expression" />
<input type="submit" />
</form>

<?php

if(isset($_GET['Expression'])){
	$input = $_GET["Expression"];
	$input0 = str_replace(' ','', $input);
	$pattern = "/^(-?(([0-9]*\.?[0-9]+)|([0-9]+\.?[0-9]*)))((\+|\+-|\*|\*-|\/|\/-|-|--)((([0-9]*\.?[0-9]+)|([0-9]+\.?[0-9]*))))*$/";
	
	if (preg_match($pattern,$input0, $matches))
	{
		
		
		$matches[0] = str_replace("--","- -", $matches[0]);
	
		@eval("\$answer=$matches[0];");
	
		if ($answer === false)
		{
			echo  "Invalid Expression: ".$input."\n";
			
		}
		else 
		{
			echo "The answer is :".$answer;
		}
		
		
	}
	else{
			echo  "Invalid Expression: ".$input."\n";
	}
	

}
?>
</body>
</html>
